﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class frmupdateczy : Form
    {
        public frmupdateczy()
        {
            InitializeComponent();
        }
        public int stuno;
        string strconn = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        private void frmupdateczy_Load(object sender, EventArgs e)
        {
            dzh();
           
        }
        public void dzh() {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            string sql = "select id,pwd,userID from [User]";
            SqlCommand cmd = new SqlCommand(sql,conn);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                textBox1.Text = reader["userID"].ToString();
                textBox2.Text = reader["id"].ToString();
                textBox3.Text = reader["pwd"].ToString();
            }
        }
          private void button1_Click(object sender, EventArgs e)
        {
            
        }

          private void button1_Click_1(object sender, EventArgs e)
          {
              
              SqlConnection conn = new SqlConnection(strconn);
              conn.Open();
              int bianhao = Convert.ToInt32(this.textBox1.Text);
              string dj = this.textBox2.Text;
              string mima = this.textBox3.Text;
              string sql = "update [User] set userID='" + bianhao + "',id='" + dj + "',pwd='" + mima + "'where userID='"+stuno+"'";
              SqlCommand cmd = new SqlCommand(sql, conn);
              int i = cmd.ExecuteNonQuery();
              if (i > 0)
              {
                  MessageBox.Show("修改成功");
              }
              else
              {
                  MessageBox.Show("修改失败");
              }
          }  
    } 
    }

 